import { Component, OnInit, ViewChild } from '@angular/core';

@Component({
  selector: 'app-dom',
  templateUrl: './dom.component.html',
  styleUrls: ['./dom.component.less']
})
export class DomComponent implements OnInit {

  // 获取DOM节点
  @ViewChild('myBox') myBox: any
  // 获取一个组件
  // @ViewChild('header') header: any

  constructor() { }

  ngOnInit(): void {
  }

  // DOM加载完成的生命周期
  ngAfterViewInit(): void {
    //Called after ngAfterContentInit when the component's view has been initialized. Applies to components only.
    //Add 'implements AfterViewInit' to the class.
    console.log(this.myBox)
    console.log(this.myBox.nativeElement) // DOM节点

    const divDOm = this.myBox.nativeElement.style.color = 'red'

    // 调用子组件的方法
    // console.log(this.header)
    // this.header.run()
    
  }

}
